package org.qiyu.live.web.starter.error;

/**
 * Created with IntelliJ IDEA.
 * Description: 自定义断言组件,当条件不满足的时候我们就抛出异常
 * User: sfx
 * Date: 2023-10-22
 * Time: 19:12
 */
public class ErrorAssert {

    /**
     * obj为空抛出异常
     *
     * @param obj           对象
     * @param qiYuBaseError 统一异常接口
     */
    public static void isNotNull(Object obj, QiYuBaseError qiYuBaseError) {
        if (obj == null) {
            throw new QiYuErrorException(qiYuBaseError.getErrorCode(), qiYuBaseError.getErrorMsg());
        }
    }

    /**
     * str为空抛出异常
     *
     * @param str           字符串对象
     * @param qiYuBaseError 统一异常接口
     */
    public static void isNotBlank(String str, QiYuBaseError qiYuBaseError) {
        if (str == null || str.trim().length() == 0) {
            throw new QiYuErrorException(qiYuBaseError.getErrorCode(), qiYuBaseError.getErrorMsg());
        }
    }

    /**
     * flag为false抛出异常
     *
     * @param flg           标志是否为false
     * @param qiYuBaseError 统一异常接口
     */
    public static void isNotBlank(boolean flg, QiYuBaseError qiYuBaseError) {
        if (!flg) {
            throw new QiYuErrorException(qiYuBaseError.getErrorCode(), qiYuBaseError.getErrorMsg());
        }
    }
}